﻿/******************************************************************************
* File description: StatMaint.qml
* Function: 统计保养页面
* Current Version: 1.1
* Author: 陈乃瑞
* Date: 2025-07-01
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.0
import "../components"
import QtCharts 2.3
import QtQuick.Window 2.12
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.2
import QtQuick.Controls 2.12
import QtMultimedia 5.14


Rectangle {
    width: parent.width
    height: parent.height
    property var typekey: []
    property var typeval: []
    property var targets: [t1, t2, t4, t5, t6, t7, t8, t9]
    onVisibleChanged: {
        var value = CExeConfig.getMaskingInformation()
        if(value[0]==="1"&&value[1]==="0"){
            pbflag=1
        }else if(value[0]==="0"&&value[1]==="1"){
            pbflag=2
        }else{
            pbflag=3
        }
        typekey=[]
        typeval=[]
        for (var j = 0; j < targets.length; j++) {
            var index = j < 2 ? j + 1 : j + 2;  // Map array indices to your original numbering
            var result = CGetMessageInterface.getStaticTotalNum(index);
            targets[j].numbv = result[0];
            targets[j].more = targets[j].numbv > result[1];
        }
        var now = new Date();
        var year = now.getFullYear();
        var month = String(now.getMonth() + 1).padStart(2, '0');
        var formattedDate = year + '-' + month;
        endDate.setText(formattedDate)
        var data=[]
        if(tabnumv<3){
            data=CGetMessageInterface.getStaticNum(tabnumv,beginDate.getText(),endDate.getText());
        }else{
            data=CGetMessageInterface.getStaticNum(tabnumv-1,beginDate.getText(),endDate.getText());
        }
        for (var i = 0; i < data.length; i++) {
            var parts = data[i].split(',');
            typekey.push(parts[0]);
            typeval.push(Number(parts[1]));
        }
        axisX.categories=typekey
        barSet.values=typeval
    }
    property int tabnumv: 1
    property int tabnum: 1
    Rectangle{
        id:allw
        y:20*dp
        width: parent.width
        height: 120*dp
        ScrollView {
            x:20*dp
            y:0*dp
            width: parent.width-40*dp
            height: parent.height
            clip: true
            Row{
                id:myColumnLayout
                spacing: 10*dp
                height: 110*dp
                width: parent.width
                TJBYTop{
                    id:t1
                    y:0*dp
                    width: (allw.width-80*dp)/5
                    picpath:"qrc:/picture/tj_p1.png"
                    topv:"设备运行时长(h)"
                    numbv: "0"
                    dcolor: tabnumv===1?"#FF7F0B":"#DEDEDE"
                    onAllcli: {
                        tabnum=1
                        tabnumv=1
                        typename.text="设备运行时长(h)"
                    }
                }
                TJBYTop{
                    id:t2
                    y:0*dp
                    width: (allw.width-80*dp)/5
                    picpath:"qrc:/picture/tj_p2.png"
                    topv:"气泵使用时长(h)"
                    numbv: "0"
                    dcolor: tabnumv===2?"#39B4FA":"#DEDEDE"
                    onAllcli: {
                        tabnum=1
                        tabnumv=2
                        typename.text="气泵使用时长(h)"
                    }
                }
                TJBYTop{
                    visible: pbflag!==1
                    id:t3
                    y:0*dp
                    width: (allw.width-80*dp)/5
                    picpath:"qrc:/picture/tj_p3.png"
                    topv:"耗材编码统计"
                    numbv: "2"
                    dcolor: tabnumv===3?"#10BA3F":"#DEDEDE"
                    onVisibleChanged: {
                        numbv = CBarCode.getBarCodeNum()
                    }
                    onMorecli: {
                        tabnum=0
                    }
                    onAllcli: {
                        tabnum=1
                        tabnumv=3
                    }
                }
                TJBYTop{
                    visible: pbflag!==2
                    id:t4
                    y:0*dp
                    width: (allw.width-80*dp)/5
                    picpath:"qrc:/picture/tj_p4.png"
                    topv:"蠕动泵(传靶)使用时长(h)"
                    numbv: "0"
                    dcolor: tabnumv===4?"#4440EC":"#DEDEDE"
                    onAllcli: {
                        tabnum=1
                        tabnumv=4
                        typename.text="蠕动泵(传靶)使用时长(h)"
                    }
                }
                TJBYTop{
                    visible: pbflag!==1
                    id:t5
                    y:0*dp
                    width: (allw.width-80*dp)/5
                    picpath:"qrc:/picture/tj_p5.png"
                    topv:"蠕动泵(纯化)使用时长(h)"
                    numbv: "0"
                    dcolor: tabnumv===5?"#7D40EC":"#DEDEDE"
                    onAllcli: {
                        tabnum=1
                        tabnumv=5
                        typename.text="蠕动泵(纯化)使用时长(h)"
                    }
                }
                TJBYTop{
                    id:t6
                    y:0*dp
                    width: (allw.width-80*dp)/5
                    picpath:"qrc:/picture/tj_p6.png"
                    topv:"压紧胶垫次数"
                    numbv: "0"
                    dcolor: tabnumv===6?"#EC4040":"#DEDEDE"
                    onAllcli: {
                        tabnum=1
                        tabnumv=6
                        typename.text="压紧胶垫次数"
                    }
                }
                TJBYTop{
                    visible: pbflag!==2
                    id:t7
                    y:0*dp
                    width: (allw.width-80*dp)/5
                    picpath:"qrc:/picture/tj_p7.png"
                    topv:"真空吸盘使用次数"
                    numbv: "0"
                    dcolor: tabnumv===7?"#5CF9FF":"#DEDEDE"
                    onAllcli: {
                        tabnum=1
                        tabnumv=7
                        typename.text="真空吸盘使用次数"
                    }
                }
                TJBYTop{
                    visible: pbflag!==2
                    id:t8
                    y:0*dp
                    width: (allw.width-80*dp)/5
                    picpath:"qrc:/picture/tj_p8.png"
                    topv:"膨胀夹具使用次数"
                    numbv: "0"
                    dcolor: tabnumv===8?"#FA39C6":"#DEDEDE"
                    onAllcli: {
                        tabnum=1
                        tabnumv=8
                        typename.text="膨胀夹具使用次数"
                    }
                }
                TJBYTop{
                    visible: pbflag!==2
                    id:t9
                    y:0*dp
                    width: (allw.width-80*dp)/5
                    picpath:"qrc:/picture/tj_p9.png"
                    topv:"溶靶瓶使用时长(h)"
                    numbv: "0"
                    dcolor: tabnumv===9?"#98BA10":"#DEDEDE"
                    onAllcli: {
                        tabnum=1
                        tabnumv=9
                        typename.text="溶靶瓶使用时长(h)"
                    }
                }
            }
        }
    }
    Rectangle{
        id:alltab
        y:180*dp
        x:20*dp
        visible: tabnumv!==3
        height: parent.height - 200*dp
        width: parent.width-40*dp
        color: "#F7F7F7"
        radius: 8
        Text {
            id:typename
            x:20*dp
            y:20*dp
            text: "设备运行时长（h）"
            font.bold: true
            font.pixelSize: config.fontsize + 3*dp
        }
        CustomComboCalendarScroll{
            id:beginDate
            y:20*dp
            x:parent.width-440*dp
            editWidth: 200*dp
            height: 40*dp
            showDay: false
            date: "2025-04"
            z:1
            onDateChanged: {
                typekey=[]
                typeval=[]
                for (var j = 0; j < targets.length; j++) {
                    var index = j < 2 ? j + 1 : j + 2;  // Map array indices to your original numbering
                    var result = CGetMessageInterface.getStaticTotalNum(index);
                    targets[j].numbv = result[0];
                    targets[j].more = targets[j].numbv > result[1];
                }
                var data=[]
                if(tabnumv<3){
                    data=CGetMessageInterface.getStaticNum(tabnumv,beginDate.getText(),endDate.getText());
                }else{
                    data=CGetMessageInterface.getStaticNum(tabnumv-1,beginDate.getText(),endDate.getText());
                }
                for (var i = 0; i < data.length; i++) {
                    var parts = data[i].split(',');
                    typekey.push(parts[0]);
                    typeval.push(Number(parts[1]));
                }
            }
        }
        Text {
            y:20*dp
            x:parent.width-240*dp
            height: 40*dp
            width: 20*dp
            text: qsTr("-")
            // 设置水平和垂直方向的对齐方式为居中对齐
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
        }
        CustomComboCalendarScroll{
            id:endDate
            y:20*dp
            x:parent.width-220*dp
            editWidth: 200*dp
            height: 40*dp
            showDay: false
            date: "2025-05"
            z:1
            onDateChanged: {
                typekey=[]
                typeval=[]
                for (var j = 0; j < targets.length; j++) {
                    var index = j < 2 ? j + 1 : j + 2;  // Map array indices to your original numbering
                    var result = CGetMessageInterface.getStaticTotalNum(index);
                    targets[j].numbv = result[0];
                    targets[j].more = targets[j].numbv > result[1];
                }
                var data=[]
                if(tabnumv<3){
                    data=CGetMessageInterface.getStaticNum(tabnumv,beginDate.getText(),endDate.getText());
                }else{
                    data=CGetMessageInterface.getStaticNum(tabnumv-1,beginDate.getText(),endDate.getText());
                }
                for (var i = 0; i < data.length; i++) {
                    var parts = data[i].split(',');
                    typekey.push(parts[0]);
                    typeval.push(Number(parts[1]));
                }
            }
        }
        ChartView
        {
            x:20*dp
            y:80*dp
            width: parent.width-40*dp
            height: parent.height - y - 20*dp
            legend.alignment: Qt.AlignBottom
            antialiasing: true   //反锯齿
            backgroundColor: "white"
            animationOptions: ChartView.NoAnimation
            //设置坐标轴
            BarCategoryAxis
            {
                id: axisX
                categories: typekey
                labelsVisible: true
            }
            ValueAxis
            {
                id: axisY
                min: 0
                max: 1000
                labelsColor:"#111111"
                tickCount: 6
                labelsVisible: true
            }
            // 柱形系列
            BarSeries
            {
                id: barSeries
                barWidth:0.8
                axisX: axisX
                axisY: axisY
                labelsPosition: AbstractBarSeries.LabelsInsideEnd//柱状条形图里面的数字位置
                labelsVisible: true		//柱状条形图里数字值是否显示，默认不显示
                BarSet {
                    id:barSet
//                    color: "#FF9A3F"
                    values: typeval
                }
            }
        }
    }
    Rectangle{
        id:jgtab
        y:180*dp
        x:20*dp
        visible: false
        height: parent.height - 200*dp
        width: parent.width-40*dp
        color: "#F7F7F7"
        radius: 8
        Text {
            x:20*dp
            y:20*dp
            text: "气罐保养指导"
            font.bold: true
            font.pixelSize: config.fontsize + 3*dp
        }
        Rectangle{
            x:parent.width*0.01
            y:80*dp
            width: parent.width*0.48
            height: 400*dp
            Image {
                width: 560*dp
                height: parent.height*0.8
                x:20*dp
                y:20*dp
                source: "qrc:/picture/tj_pic.jpg"
                fillMode: Image.PreserveAspectFit
            }
        }
        Rectangle{
            x:parent.width*0.51
            y:80*dp
            width: parent.width*0.48
            height: parent.height*0.8
            color: "white"
            Text {
                x:20*dp
                y:20*dp
                text: qsTr("气罐保养指导 \n\n查看压力容器储气罐的罐体顶上的压力安全阀是否正常。 \n\n时刻留意储气罐的压力表数值和位置的好坏与正常,释放压力时正常")
            }
        }
    }
    //  条码页
    StatMaintBarCode{
        y:180*dp
        x:20*dp
        visible: tabnumv === 3
        height: parent.height - 200*dp
        width: parent.width-40*dp
        onUpdateCodeNum: {
            t3.numbv = num
        }
    }
}
